package com.example.bianproject.Adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.bianproject.Model.UModel;
import com.example.bianproject.R;

import java.util.List;

public class UAdapter extends RecyclerView.Adapter<UAdapter.ViewHolder> {

    private List<UModel> mUModle;

    static class ViewHolder extends RecyclerView.ViewHolder{
        private TextView tvName, tvContract, tvPrice, tvMinus;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.u_name);
            tvContract = itemView.findViewById(R.id.u_contract);
            tvPrice = itemView.findViewById(R.id.u_price);
            tvMinus = itemView.findViewById(R.id.u_minus);
        }
    }

    public UAdapter(List<UModel> model){
        mUModle = model;
    }

    @NonNull
    @Override
    public UAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_u, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull UAdapter.ViewHolder holder, int position) {
        UModel uModel = mUModle.get(position);
        holder.tvName.setText(uModel.getName());
        holder.tvName.setTextColor(Color.RED);
        holder.tvContract.setText(uModel.getContract());
        holder.tvContract.setTextColor(Color.RED);
        holder.tvPrice.setText(uModel.getPrice());
        holder.tvPrice.setTextColor(Color.RED);
        holder.tvMinus.setText(uModel.getMinus());
        holder.tvMinus.setTextColor(Color.RED);
    }

    @Override
    public int getItemCount() {
        return mUModle.size();
    }
}
